// pages/teachernews/teachernews.js
var app = getApp()
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getteachermessage: app.data.url +'/zhongxue/maoapi/getteachermessage',
    shuju:[],
    page:1,
    shus: [
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      { name: "张老师", src: app.data.url +"/uploads/zhongxue/kteacher.png", date: "2017-06-04 16:40", xiaoxi: "1.请熟读被背诵“岳阳楼记”，预习“出师表”和熟读并理解翻译前两段请熟读被背诵岳阳楼记“，预习”出一表“和熟读并理解翻译前两段" },
      ],
      id:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.setData({id:id});
    this.getData();
  },
  getData:function(){
    var page = this.data.page;
    var id = this.data.id;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration: app.data.quanbushijian
      })
      return
    }
    var user = wx.getStorageSync('user');
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    wx.request({
      url: that.data.getteachermessage,
      data: {token:user.token,page:page,id:id},
      header: {},
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        var data = res.data;
        console.log(data);
        // return
       if(data.code==200){
         var newshuju = data.data;
         if(newshuju.length<10){
           that.setData({page:0})
         }else{
           that.setData({page:page+1})
         }
         var shuju = that.data.shuju;
         shuju = ea.addArray(shuju,newshuju);
         console.log(shuju);
         that.setData({shuju:shuju})
       }else{
         wx.showToast({
           title: data.msg,
           icon:'none',
           duration: app.data.quanbushijian
         })
       }
      },
      fail: function(res) {},
      complete: function(res) {
        wx.hideLoading()
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({page:1,shuju:[]})
    this.getData();
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})